<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="com.minshenglife.zanzan.pub.Config" %>
	<%
	String rootPath = Config.getProperty(Config.WX_BASEURL);//应用的根路径
	%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=rootPath%>">
    <title>角色管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
  </head>
  
  <body>
    <table border="1px" style="width: 100%;" > 
    	<tr height="50px">
			<td colspan="4" >
				<input name="findUserName" type="text" id="findName"/>
				<input type="button" onclick="doUserName()" value="用户查找"/>
			</td>
		</tr>
    	<tr>
			<td  width="15%" align="center">姓名</td>
			<td  width="25%" align="center">部门</td>
			<td  width="15%" align="center">职位</td>
			<td  width="10%" align="center">职级</td>
			<td  width="25%" align="center">日志职位</td>
			<td  width="25%" align="center">日志职级</td>
			<td  width="15%" align="center">操作</td>
			<c:choose>
			   <c:when test="${add}">  
			      <td width="10%"  align="center">管理员操作</td>
			   </c:when>
			   <c:otherwise> 
			   </c:otherwise>
			</c:choose>
		</tr>
		<c:forEach items="${page.rows}" var="each" varStatus="vars">
			<tr>
				<td align="center">
					${each.emp_name}
				</td>
				<td align="center">
					${each.dept_name}
				</td>
				<td align="center">
					${each.posiName}
				</td>
				<td align="center">
					${each.postId}
				</td>
				<td align="center">
					<c:choose>
					   <c:when test="${each.tdDept_name!= null}"> 
					   		${each.tdDept_name}
					   </c:when>
					   <c:otherwise>
					   		没有设置
				  	   </c:otherwise>
					</c:choose>
				</td>
				<td align="center">
					<c:choose>
					   <c:when test="${each.tdPostId!= null}"> 
					   		${each.tdPostId}
					   </c:when>
					   <c:otherwise>
					   		没有设置
				  	   </c:otherwise>
					</c:choose>
				</td>
				<td align="center">
					<input type="button" onclick="doRoleUpdate('${each.empId}');" value="&nbsp;&nbsp;修改职位&nbsp;&nbsp;">
				</td>
				<td>
				<c:choose>
				   <c:when test="${add}"> 
				    <c:choose>
					   <c:when test="${each.mpEmpId == null}"> 
					   		<input type="button"  onclick="addManager('${each.empId}');" value="&nbsp;设置为管理员&nbsp;"> 
					   </c:when>
					   <c:otherwise>
					   		<input type="button" id="deleteManager" onclick="deleteManager('${each.empId}');" value="&nbsp;取消管理员&nbsp;"> 
				  	   </c:otherwise>
					</c:choose>
				   </c:when>
				   <c:otherwise> 
			  	   </c:otherwise>
				</c:choose>
				</td>
			</tr>
		</c:forEach>
    </table>
    <p>${addManagermsg}</p>
    <form id="pageForm" name="pageForm" action="" method="get">
         <input id="pageNo" type="hidden" name="pageNo" value="${page.pageNo}"/>
         <input id="pageSize" type="hidden" name="pageSize" value="${page.pageSize}"/>
         <br />
         <input type="button" style="margin-left:350px; color:#000;text-decoration:none;" onclick=upPageChange() value="上一页">
     	<input type="button" style="margin-left:350px; color:#000;text-decoration:none;" onclick=downPageChange() value="下一页">
     </form>
  </body>
</html>
<script type="text/javascript" src="<%=rootPath%>/jsp/power/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript">

	/**
	 *根据用户名搜索用户
	 */
	function doUserName(){
		var userName = document.getElementById("findName").value;
		if(userName == null){
			alert("请输入要搜索用户名");
		}else{
			window.location.href = "<%=rootPath%>/userRole/findUserName.power?userName="+userName;
		}
	}
	/**
	 * 修改指定的用户角色
	 * @param {Object} id
	 */
	function doRoleUpdate(empId) {
		//alert(empId);
		window.location.href = "<%=rootPath%>/userRole/updateUserRole.power?empId="+empId;
	}
	/**
	 *上一页
	 */
	function upPageChange(){
		 var pageNo = document.getElementById("pageNo").value;
         document.getElementById("pageNo").value= pageNo-1;
         pageForm.action = "<%=rootPath%>/userRole/loadUserRole.power";
         pageForm.target="_self";
         pageForm.submit();
	}
	
	/**
	 *下一页
	 */
	function downPageChange(){
		 var pageNo = document.getElementById("pageNo").value;
		 pageNo=parseInt(pageNo,10);
         document.getElementById("pageNo").value= pageNo+1;
         //alert(document.getElementById("pageNo").value);
         pageForm.action = "<%=rootPath%>/userRole/loadUserRole.power";
         pageForm.target="_self";
         pageForm.submit();
	}
	
	/**
	 *添加管理员
	 */
	function addManager(empId){
		window.location.href = "<%=rootPath%>/userRole/addManagerEmp.power?empId="+empId;
	}
	function deleteManager(empId){
		$.ajax({
			url:"<%=rootPath%>/userLogin/deleteManagerEmp.power",
			type: 'GET',
			dataType: "TEXT",
			data:'empId='+empId,
			async: false,
			success: function (obj){
				alert(obj);
				window.location.href ="<%=rootPath%>/userRole/loadUserRole.power";
			}
		})
	}
</script>
